import { SinglyLinkedList } from '@/library/libs/rt-singly-linked-list'

export class LinkedListQueue<V = any, R = any> extends SinglyLinkedList<V, R> {
  /**
   * @description The `enqueue` function adds a new node to the end of a singly linked list queue.
   * @param {V} value value of SinglyLinkedListQueueNode
   * @returns {void}
   */
  enqueue(value: V): void {
    this.push(value)
  }

  /**
   * @description The `dequeue` function removes first node.
   * @returns {V} value of SinglyLinkedListQueueNode
   */
  dequeue(): V | undefined {
    return this.shift()
  }

  /**
   * @description The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as the current instance.
   * @returns a new instance of `LinkedListQueue` with the same values as the original `LinkedListQueue`.
   */
  override clone(): LinkedListQueue<V, R> {
    return new LinkedListQueue<V, R>(this, { toValueFn: this.getToValueFn })
  }
}
